<template>
	<view class="goods-detail">
		<g-navbar title="商品详情" />
		<goodsSwiper :detail="detail" />
		<goodsDetailModule :detail="detail" />
		<view class="title">商品详情</view>
		<goodsPosterList :detail="detail" />
		<goodsNav @open="open" />
		<goodsOrderPopup ref="goodsOrderPopupRef" :detail="detail" :agentMin="agentMin"/>
	</view>
</template>

<script lang="ts" setup>
	import goodsSwiper from './components/goods-swiper/goodsSwiper.vue';
	import goodsDetailModule from './components/goods-detail-module/goodsDetailModule';
	import goodsPosterList from './components/goods-poster-list/goodsPosterList.vue';
	import goodsNav from './components/goods-nav/goodsNav.vue';
	import goodsOrderPopup from './components/goods-order-popup/goodsOrderPopup';
	import { ORDER_TYPE } from '@/enum/goods';
	import { reactive, ref, Ref } from 'vue';
	import { IGoodsOrderPopupExpose } from './components/goods-order-popup/types';
	import { onLoad } from '@dcloudio/uni-app';
	import REST_URL from '@/http/http.restUrl';
	import { useStore } from 'vuex';
	import { GET_STORE_USERINFO } from '@/store/gettersType';

	const store = useStore();




	const goodsOrderPopupRef : Ref<IGoodsOrderPopupExpose | null> = ref(null);

	const open = (e : ORDER_TYPE) => {
		goodsOrderPopupRef.value?.open(e);
	}

	const detail : Ref<IGoods | null> = ref(null);

	const agentMin : Ref<number> = ref(10);



	onLoad(async (options) => {
		await uni.loginManger.$interceptor;
		await getGoodsDetail(options!.id);
		await getAgentMinCount();
	})


	const getAgentMinCount = async () => {
		const { data } = await uni.http.POST(REST_URL.getMinOrderCount, {
			customer_id: store.getters[GET_STORE_USERINFO].id,
		})
		// console.log('booking_min_number',data.booking_min_number)
		agentMin.value = Number(data.booking_min_number);
	}

	const getGoodsDetail = async (id:number) => {
		const data : IGoods = (await uni.http.POST(REST_URL.getGoodsDetailById, {
			// customer_id: store.state.userInfo.id,
			product_id: id,
		})).data
		detail.value = data;
	}
</script>

<style scoped lang="scss">
	@import "./goodsDetail.scss";
</style>